
package com.example.swordjava;


import java.util.ArrayList;

public class Test74 {

    public static void main(String[] args) {

        int[][] aa = {{1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12},
                {13, 14, 15, 16}};

        int a = 1;
        int b = 4;
        int c = 4 * (b - a) / 2;

        System.out.println(Math.pow(1, 10));
        System.out.println(c);

    }

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }
    }

    /**
     * JZ74 和为S的连续正数序列
     * 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。
     * 但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,
     * 他就得到另一组连续正数和为100的序列:18,19,20,21,22。现在把问题交给你,你能不能也很快的找出所有和为S的连续正数序列?
     */

    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
        // write code here

        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        int low = 1;
        int high = 2;

        while (low < high) {
            int cur = (low + high) * (high - low + 1) / 2;
            if (sum == cur) {
                ArrayList<Integer> list = new ArrayList<>();
                for (int i = low; i <= high; i++) {
                    list.add(i);
                }
                res.add(list);
                low++;
            } else if (sum > cur) {
                high++;
            } else if (sum < cur) {
                low++;
            }
        }
        return res;
    }

}














